package com.wz.device.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wz.common.utils.text.Convert;
import com.wz.device.entity.BasDeviceRecord;
import com.wz.device.mapper.BasDeviceRecordMapper;
import com.wz.device.service.BasDeviceRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author qiqi
 * @since 2021-10-22
 */
@Service
public class BasDeviceRecordServiceImpl extends ServiceImpl<BasDeviceRecordMapper, BasDeviceRecord> implements BasDeviceRecordService {

    @Autowired
    private BasDeviceRecordMapper basDeviceRecordMapper;


    @Override
    public List<BasDeviceRecord> selectBasDeviceRecordList(BasDeviceRecord basDeviceRecord) {
        // 生成数据权限过滤条件
        return basDeviceRecordMapper.selectBasDeviceRecordList(basDeviceRecord);
    }

    @Override
    public int insertBasDeviceRecord(BasDeviceRecord basDeviceRecord) {
        // 新增设备维护记录信息
        try {
            String s = String.valueOf(System.currentTimeMillis());
            String substring = s.substring(s.length() - 6);
            basDeviceRecord.setId(substring);
            int rows = basDeviceRecordMapper.insertBasDeviceRecord(basDeviceRecord);
            return rows;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public BasDeviceRecord selectBasDeviceRecord(String id) {
        return basDeviceRecordMapper.selectBasDeviceRecordById(id);
    }

    @Override
    public int updateBasDeviceRecord(BasDeviceRecord basDeviceRecord) {
        try {
            return basDeviceRecordMapper.updateBasDeviceRecord(basDeviceRecord);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public int deleteBasDeviceRecordByIds(String ids) {
        try {
            String[] deviceRecordIds = Convert.toStrArray(ids);
            return basDeviceRecordMapper.deleteBasDeviceRecordByIds(deviceRecordIds);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
}
